$(function (){
      var mySwiper = new Swiper('.swiper-container',{
          speed:800,
          // loop: true,
          // autoplay: {
          //     delay: 5000,//1秒切换一次
          //     disableOnInteraction: false,
          // },
         on: {
            slideChangeTransitionStart: function(){
                $("video").map(function (index,ele){
                    var id = $(ele).attr('data-id');
                    var num = id.split("_")[1];
                    var videoDom = 'video_' + num;
                    var video = document.getElementById(videoDom);
                    video.pause();
                })
            }
        },
        pagination: {
            el: '.swiper-pagination',
        }
    })

    new Swiper('.swiper',{
        slidesPerView: 'auto'
    })

    $("video").map(function (index,ele){
        var id = $(ele).attr('data-id');
        var num = id.split("_")[1];
        var videoDom = 'video_' + num;
        var btn = '#video_btn_' + num;
        var btn_id = 'video_btn_' + num;
        var coverStr =  '#video_' + num  + '_cover';
        var video = document.getElementById(videoDom);

        $(btn).click(function () {
            // mySwiper.autoplay.start();
            video.play();
        })

        document.getElementById(btn_id).addEventListener('touchstart',function (e) {
            // mySwiper.autoplay.stop();
            video.play();
        },false);

        video.addEventListener('pause', function() {
            // cover.style.display = 'block'; // 显示封面
            $(coverStr).show();
            $(btn).show();
            // mySwiper.autoplay.start();
        });

        video.addEventListener('play', function() {
            // cover.style.display = 'none'; // 隐藏封面
            // mySwiper.autoplay.stop();
            $(coverStr).hide();
            $(btn).hide();
        });
    })
})
